/*
 * Copyright (c) 2014-2019 Yunding Network Technology(Beijing) Co., Ltd
 * All Rights Reserved.
 * Confidential and Proprietary - Yunding Network Technology.
 * Description: app header 结构 runing status 结构
 */

#ifndef __IMAGE_STRUCT_H
#define __IMAGE_STRUCT_H

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#define WHOLE_APP_MAX_LIMIT_SIZE    (456*1024)

#define  APP_HEADER_CRC_DATA_LEN    (8)
#define  APP_HEADER_SIZE            (sizeof(app_header_t))

#define  APP_RUNING_STATUS_CRC_DATA_LEN    (8)
#define  APP_RUNING_STATUS_SIZE     (sizeof(app_runing_status_t))

#define  TRUE_FLAG_MAGIC            (0xFEDCBA98)
#define  FALSE_FLAG_MAGIC           (0x89ABCDEF)


#define  APP_HEADER_MAGIC           (0xABCDABCD)
#define  APP_RUNING_STATUS_MAGIC    (0xDCBADCBA)


#define  APP_TYPE_1_MAGIC           (0x11223344)
#define  APP_TYPE_2_MAGIC           (0x44332211)


// APP 结构
typedef struct {
    uint32_t  header_len;
    uint32_t  header_crc;

    uint32_t  magic;
    uint32_t  app_type; //1 : app_1 , 2 : app_2
    uint32_t  version; //固件版本
    uint32_t  code_len;
    uint32_t  code_crc;
} app_header_t __attribute__((aligned(sizeof(uint32_t))));



// runing status 结构
typedef struct {
    uint32_t  runing_status_len;
    uint32_t  runing_status_crc;

    uint32_t  magic;
    uint32_t  ota_flag;//标记是否需要OTA
    uint32_t  ota_type;//标记需要OTA的固件type APP_1 ,APP_2

    uint32_t  firmware_runing_type; //标记重启前固件运行type
    uint32_t  firmware_reload_flag; //标记是否需要boot进行切换
    uint32_t  firmware_reload_type; //标记需要切换的固件type
    uint32_t  firmware_verify_flag; //标记是否需要校验固件

} app_runing_status_t __attribute__((aligned(sizeof(uint32_t))));



//自定义复位原因
#define APP_RESET_UNKNOW            0x1000u
#define APP_RESET_RELOAD_APP_1      0x1001u
#define APP_RESET_RELOAD_APP_2      0x1002u
#define APP_RESET_OTA_START_APP_1   0x1003u
#define APP_RESET_OTA_START_APP_2   0x1004u


#endif

